﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.IO;

///This class will be the base run for the Game Screen.
///it'll check all entities and the map separately, while allowing communication between.
///I'll also make the Tile Map(s) update often.
///

namespace MyImaginaryFriends_Redux.Screens
{
    class GameplayScreen
    {

        #region Variables

        private bool b_cmd = false;

        private State GamePlayScreenState;
        private bool b_LoadContentReturn1;
        private bool b_LoadContentReturn2;

        public bool DeathScreenActive;
        public bool ReinitializeCommand;

        public bool b_fromNewGame;

        public bool b_WinGame = false;

        private Debug Debug;

        private Texture2D DeathScreen;
        private Texture2D WinScreen;

        private ScriptedEvent ScriptEvent;

        private GamePlayScreen_Classes.TileMap_Visual VisualMap;
       // private GamePlayScreen_Classes.TileMap_Visual BackgroundMap;
        private GamePlayScreen_Classes.TileMap_Background BackgroundMap;
        private GamePlayScreen_Classes.TileMap_Colliding CollisionMap;

        private GamePlayScreen_Classes.PlayerEntity Player;
        private GamePlayScreen_Classes.FriendEntity Friend;

        private GamePlayScreen_Classes.Camera Camera;

        private InGamePause PauseMenu;

        private bool DebugMode = false;

        private string s_currentRegion = "StartingRoom";
        private string s_previousRegion;

        SpriteFont DebugFont;

        #endregion

        //CONSTRUCT AND INITIAILZE!!!
        public GameplayScreen()
        {
            GamePlayScreenState = State.Hidden;
            b_LoadContentReturn1 = false;
            b_LoadContentReturn2 = false;

            VisualMap = new GamePlayScreen_Classes.TileMap_Visual();
            BackgroundMap = new GamePlayScreen_Classes.TileMap_Background();
            CollisionMap = new GamePlayScreen_Classes.TileMap_Colliding();

            Player = new GamePlayScreen_Classes.PlayerEntity();
            Friend = new GamePlayScreen_Classes.FriendEntity();

            Camera = new GamePlayScreen_Classes.Camera();

            PauseMenu = new InGamePause();

            Debug = new Debug();

            ScriptEvent = new ScriptedEvent();

            

            //Enemy = new GamePlayScreen_Classes.EnemyEntity();


        }

        public void LoadContent(ContentManager content, Screens.MainMenu TitleScreen, Screens.TitleOptionsMenu OptionsScreen)
        {
            DeathScreen = content.Load<Texture2D>("MenuContent/DeathScreen");
            WinScreen = content.Load<Texture2D>("MenuContent/WinScreen");
            DebugFont = content.Load<SpriteFont>("MenuContent/Arial");
            PauseMenu.LoadContent(content);

            Debug.LoadContent(content);

            if (GamePlayScreenState == State.Loading)
            {

                ReinitializeCommand = false;

                if (b_fromNewGame)//load a new game file.
                {
                   

                    b_LoadContentReturn2 = CollisionMap.LoadContent(content, s_currentRegion, Player.b_RequestActivate_GateTrigger_BlockRoom2ToRoomA, Player.b_hasKnifeKey);
                   // BackgroundMap.LoadContent(content, s_currentRegion, Player.b_RequestActivate_GateRoom_LeverTrigger);
                    b_LoadContentReturn1 = VisualMap.LoadContent(content, s_currentRegion, Player.b_RequestActivate_GateTrigger_BlockRoom2ToRoomA, Player.b_hasKnifeKey);

                    Player.LoadContent(content);//loadcontentfromnewgame
                    Friend.LoadContent(content);//from newgame
                    //Enemy.LoadContent(content);//fromnewgame
                    //this will have a couple of checks from a data packet.
                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("StartingRoom_Spawn"));
                
                    //Enemy.Spawn(CollisionMap.GetEnemySpawnPoint("First_One"), GamePlayScreen_Classes.EnemyEntity.EnemyType.Knife);
                }
                else if (!b_fromNewGame)
                {
                    //load file here, baby.
                    //Load From Save File.
                }
                
                //what level is the player on? has the player just started the game?
                //what's the current progress? etc. to check and see what spawn point string to pull.
            }
         

        }

        public void Update(ContentManager content, GameTime gameTime, InputHandler input, Screens.MainMenu TitleScreen, Screens.TitleOptionsMenu OptionsScreen)
        {
            Debug.Update(input);
            ScriptEvent.Update(gameTime, Player);

            if (Player.b_CanEndGame)
            {
                b_WinGame = true;
            }

            if (b_LoadContentReturn1 && b_LoadContentReturn2)
                GamePlayScreenState = State.Active;


            if (GamePlayScreenState == State.Active && !Player.GetSetRequestPauseMenuOpen)
            {
                if (!ScriptEvent.b_IsEventActive && Player.b_IsAlive)
                {
                    CollisionMap.Update(gameTime, Player, input);
                    //this shit will update EVERYTHING
                    Player.Update(gameTime, input, CollisionMap, GamePlayScreenState);
                    Friend.Update(gameTime, Player, CollisionMap);

                    LevelMovementHandler(content);
                }
                else if(!Player.b_IsAlive)
                {

                    DeathScreenActive = true;
                    MediaPlayer.Stop();

                }
                else
                {
                    //Panic
                }

                if (DeathScreenActive)
                {
                    if (input.GetKBStateSingle(Keys.Enter) || input.GetGPStateSingle(Buttons.Start))
                    {

                        Player.b_IsAlive = true;
                        DeathScreenActive = false;
                       

                        GamePlayScreenState = State.Hidden;

                        ReinitializeCommand = true;
                        TitleScreen.SetMainMenuState(State.Active);
                    }
                }

                if (b_WinGame)
                {
                    MediaPlayer.Stop();
                    if (input.GetKBStateSingle(Keys.Enter) || input.GetGPStateSingle(Buttons.Start))
                    {
                      
                        GamePlayScreenState = State.Hidden;
                        ReinitializeCommand = true;
                        TitleScreen.SetMainMenuState(State.Active);
                    }

                }

            }

           

            PauseMenu.Update(gameTime, input, this, Player);     
  
        


            if (input.GetKBStateSingle(Keys.Escape) || input.GetGPStateSingle(Buttons.BigButton))
            {
                //exit command
                b_cmd = true;
            }
        }

        public bool PassExitCommand()
        {
            return b_cmd;
        }

        public void LevelMovementHandler(ContentManager content)
        {
            #region StartingRoom
            if (s_currentRegion == "StartingRoom")
            {
                if (Player.b_RequestActivate_Door_StartToHallway)//this needs to check against the player's door that they're colliding with.
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                //    BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("Hallway_To_StartingRoom"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "Hallway";
                    Player.b_RequestActivate_Door_StartToHallway = false;
                
                }

            }
            #endregion

            #region Hallway
            if (s_currentRegion == "Hallway")
            {
                if (Player.b_RequestActivate_Door_HallwayToStart)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "StartingRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                //    BackgroundMap.LoadContent(content, "StartingRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "StartingRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                   
                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("StartingRoom_To_Hallway"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "StartingRoom";

                    Player.b_RequestActivate_Door_HallwayToStart = false;
                }

                if (Player.b_RequestActivate_HallToA)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                 //   BackgroundMap.LoadContent(content, "RoomA", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomA_To_Hallway"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomA";

                    Player.b_RequestActivate_HallToA = false;
                }

                if (Player.b_RequestActivate_HallToB)
                {
                    if (Player.b_RequestActivate_GateRoom_LeverTrigger)
                    {
                        b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomB", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                  //      BackgroundMap.LoadContent(content, "RoomB", Player.b_IsGateActive);
                        b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomB", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                        Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomB_To_Hallway"));
                        if (Friend.b_IsSummoned)
                        {
                            //if friend is lamp.
                            Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                        }

                        s_currentRegion = "RoomB";

                        Player.b_RequestActivate_HallToB = false;
                    }
                }

                if (Player.b_RequestActivate_HallToD)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomD", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                 //   BackgroundMap.LoadContent(content, "RoomD", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomD", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomD_To_Hallway"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomD";

                    Player.b_RequestActivate_HallToD = false;
                }
            }
            #endregion

            #region Room A
            if (s_currentRegion == "RoomA")
            {
                if (Player.b_RequestActivate_AToHall)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("Hallway_To_RoomA"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "Hallway";

                    Player.b_RequestActivate_AToHall = false;
                }

                if (Player.b_RequestActivate_AToPaintRm1)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom1_To_RoomA"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom1";

                    Player.b_RequestActivate_AToPaintRm1 = false;
                }

            }

            #endregion

            #region PaintingRoom1

            if (s_currentRegion == "PaintingRoom1")
            {
                if (Player.b_RequestActivate_PaintingRoom1_To_RoomA)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomA_To_PaintingRoom1"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomA";

                    Player.b_RequestActivate_PaintingRoom1_To_RoomA = false;
                }

                if (Player.b_RequestActivate_PaintingRoom1_To_PaintingRoom2)
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom2", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom2", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom2_To_PaintingRoom1_Fall"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom2";

                    Player.b_RequestActivate_PaintingRoom1_To_PaintingRoom2 = false;
                }
            }
            #endregion

            #region Painting Room2

            if (s_currentRegion == "PaintingRoom2")
            {
                if (Player.b_RequestActivate_PaintingRoom2_to_PaintingRoom1)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom1_To_PaintingRoom2"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom1";

                    Player.b_RequestActivate_PaintingRoom2_to_PaintingRoom1 = false;
                }

                if (Player.b_RequestActivate_PaintingRoom2_To_PaintingRoom3)
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom3", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom3", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom3_To_PaintingRoom2_Fall"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom3";

                    Player.b_RequestActivate_PaintingRoom2_To_PaintingRoom3 = false;
                }
            }

            #endregion

            #region Painting Room 3

            if (s_currentRegion == "PaintingRoom3")
            {
                if (Player.b_RequestActivate_PaintingRoom3_To_PaintingRoom1)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom1_To_PaintingRoom2"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom1";

                    Player.b_RequestActivate_PaintingRoom3_To_PaintingRoom1 = false;
                }

                if (Player.b_RequestActivate_PaintingRoom3_To_GateRoom)
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "GateRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "GateRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("GateRoom_To_PaintingRoom4"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "GateRoom";

                    Player.b_RequestActivate_PaintingRoom3_To_GateRoom = false;
                }
            }
            #endregion

            #region Room B // NEED TO UPDATE


            if (s_currentRegion == "RoomB")
            {
                if (Player.b_RequestActivate_BToHall)
                {
                    if (Player.b_RequestActivate_RoomBDoorTrigger)//SHOULD BE FRIEND< COLLISION IS STILL BUGGY
                    { //|:[ seriously?
                        b_LoadContentReturn1 = CollisionMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                        //BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                        b_LoadContentReturn2 = VisualMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                        Player.Spawn(CollisionMap.GetPlayerSpawnPoint("Hallway_To_RoomB"));
                        if (Friend.b_IsSummoned)
                        {
                            //if friend is lamp.
                            Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                        }

                        s_currentRegion = "Hallway";

                    }
                    Player.b_RequestActivate_BToHall = false;

                }
                if (Player.b_RequestActivate_BtoC)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomC", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                 //   BackgroundMap.LoadContent(content, "RoomC", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomC", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomC_To_RoomB"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomC";

                    Player.b_RequestActivate_BtoC = false;
                }
            }

            #endregion

            #region Room C // NEED TO UPDATE
            if (s_currentRegion == "RoomC")
            {
                if (Player.b_RequestActivate_CToB)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomB", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                  //  BackgroundMap.LoadContent(content, "RoomB", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomB", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomB_To_RoomC"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomB";

                    Player.b_RequestActivate_CToB = false;
                }
            }
            #endregion


            #region Room D
            if (s_currentRegion == "RoomD")
            {
                if (Player.b_RequestActivate_DToHall)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                   // BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "Hallway", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("Hallway_To_RoomD"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "Hallway";

                    Player.b_RequestActivate_DToHall = false;
                }

                if (Player.b_RequestActivate_DToBackRoom1)
                {
                    if (Player.b_RequestActivate_RoomD_PlateTrigger_Unlock_BlockRoom1)
                    {
                        b_LoadContentReturn1 = CollisionMap.LoadContent(content, "BlockRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                        //BackgroundMap.LoadContent(content, "GateRoom", Player.b_IsGateActive);
                        b_LoadContentReturn2 = VisualMap.LoadContent(content, "BlockRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                        Player.Spawn(CollisionMap.GetPlayerSpawnPoint("BlockRoom1_To_RoomD"));
                        if (Friend.b_IsSummoned)
                        {
                            //if friend is lamp.
                            Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                        }

                        s_currentRegion = "BlockRoom1";

                       
                    }

                    Player.b_RequestActivate_DToBackRoom1 = false;
                }
            }
            #endregion


            #region Block Room 1
            if (s_currentRegion == "BlockRoom1")
            {
                if (Player.b_RequestActivate_BlockRoom1ToRoomD)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomD", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //BackgroundMap.LoadContent(content, "GateRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomD", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomD_To_BlockRoom1"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomD";

                    Player.b_RequestActivate_BlockRoom1ToRoomD = false;
                }

                if (Player.b_RequestActivate_BlockRoom1_To_BlockRoom2)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "BlockRoom2", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //BackgroundMap.LoadContent(content, "GateRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "BlockRoom2", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("BlockRoom2_To_BlockRoom1"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "BlockRoom2";

                    Player.b_RequestActivate_BlockRoom1_To_BlockRoom2 = false;
                }
            }

            #endregion


            #region BLock Room 2
            if (s_currentRegion == "BlockRoom2")
            {
                if (Player.b_RequestActivate_BlockRoom2_To_BlockRoom1)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "BlockRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //BackgroundMap.LoadContent(content, "GateRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "BlockRoom1", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("BlockRoom1_To_BlockRoom2"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "BlockRoom1";

                    Player.b_RequestActivate_BlockRoom2_To_BlockRoom1 = false;
                }

                if (Player.b_RequestActivate_BlockRoom2_To_RoomA)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //BackgroundMap.LoadContent(content, "GateRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomA_To_BlockRoom2"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomA";

                    Player.b_RequestActivate_BlockRoom2_To_RoomA = false;
                }
            }
            #endregion


            #region Gate Room
            if (s_currentRegion == "GateRoom")
            {
                if (Player.b_RequestActivate_GateRoom_To_PaintingRoom4)
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "PaintingRoom4", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //  BackgroundMap.LoadContent(content, "FriendRoom", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "PaintingRoom4", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("PaintingRoom4_to_GateRoom"));
                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "PaintingRoom4";


                    Player.b_RequestActivate_GateRoom_To_PaintingRoom4 = false;
                }
            }
            #endregion

            #region Painting Room 4//BUG FOR 4TOGATE

            if (s_currentRegion == "PaintingRoom4")
            {
                if (Player.b_RequestActivate_PaintingRoom4_To_GateRoom)//BUG FIX AFTER MAP IS DONE
                {
                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "GateRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "GateRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("GateRoom_To_PaintingRoom4"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "GateRoom";

                    Player.b_RequestActivate_PaintingRoom4_To_GateRoom = false;
                }

                if (Player.b_RequestActivate_PaintingRoom4_To_MusicBoxRoom)
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "MusicBoxRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "MusicBoxRoom", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("MusicBoxRoom_To_RoomA"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "MusicBoxRoom";

                    Player.b_RequestActivate_PaintingRoom4_To_MusicBoxRoom = false;
                }
            }
            #endregion

            #region MusicBoxRoom
            if (s_currentRegion == "MusicBoxRoom")
            {
                if (Player.b_RequestActivate_MusicBoxRoom_To_RoomA)
                {

                    b_LoadContentReturn1 = CollisionMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);
                    //   BackgroundMap.LoadContent(content, "Hallway", Player.b_IsGateActive);
                    b_LoadContentReturn2 = VisualMap.LoadContent(content, "RoomA", Player.b_isRoomAGateActive, Player.b_hasKnifeKey);

                    Player.Spawn(CollisionMap.GetPlayerSpawnPoint("RoomA_To_PaintingRoom1"));

                    if (Friend.b_IsSummoned)
                    {
                        //if friend is lamp.
                        Friend.Spawn(Player, GamePlayScreen_Classes.FriendType.Lamp);
                    }

                    s_currentRegion = "RoomA";

                    Player.b_RequestActivate_MusicBoxRoom_To_RoomA = false;
                }
            }

            #endregion



        }

        public State GetGamePlayScreenState()
        {
            return GamePlayScreenState;
        }

        public void SetGamePlayScreenState(State In_State)
        {
            GamePlayScreenState = In_State;
        }

        public string GetCurrentRegion()
        {
            return s_currentRegion;
        }

        public string GetPreviousRegion()
        {
            return s_previousRegion;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
           
            if (GamePlayScreenState == State.Active || Player.GetSetRequestPauseMenuOpen)
            {
                Camera.ScrollCamera(spriteBatch, Player, CollisionMap);
                //Zoom Matrix

                Matrix ZoomMatrix = Matrix.CreateScale(2.0f, 2.0f, 0.0f);
                Matrix CameraTransform = Matrix.CreateTranslation(-Camera.v2Position.X, -Camera.v2Position.Y, 0.0f) * ZoomMatrix;

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, CameraTransform);
               // BackgroundMap.Draw(spriteBatch, Camera, CollisionMap);
                VisualMap.Draw(spriteBatch, Camera, CollisionMap);
                CollisionMap.DrawEnemies(spriteBatch);
                CollisionMap.DrawCollectables(spriteBatch);
                CollisionMap.DrawPushables(spriteBatch);
                Friend.Draw(spriteBatch, Player);
                Player.Draw(spriteBatch);
                PauseMenu.Draw(spriteBatch);

                spriteBatch.End();

                //spriteBatch.Begin();
                //Debug.Draw(spriteBatch, Player, Friend, Camera, this, ScriptEvent);
                //spriteBatch.End();

               
            }

            if (DeathScreenActive)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(DeathScreen, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White);
                spriteBatch.End();
            }

            if (b_WinGame)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(WinScreen, new Vector2(spriteBatch.GraphicsDevice.Viewport.X, spriteBatch.GraphicsDevice.Viewport.Y), Color.White);
                spriteBatch.End();
            }
        }

    }
}
